import axios from 'axios';

const BASE_URL = 'http://localhost:8080/Hotels';

//查询所有酒店
export const listHotels = async () => {
    try {
        const response = await axios.get(BASE_URL);
        return response.data;
    } catch (error) {
        console.error('Error listing flights:', error.response ? error.response.data : error.message);
        throw error;
    }

};

//更新酒店
export const updateHotel = async (hotel) => {
    try {
        const response = await axios.put(BASE_URL,hotel);
        return response.data;
    } catch (error) {
        console.error('Error listing flights:', error.response ? error.response.data : error.message);
        throw error;
    }
};

//删除指定id酒店
export const deleteHotel = async (id) => {
    try {
        const response = await axios.delete(`${BASE_URL}/${id}`);
        return response.data;
    } catch (error) {
        console.error('Error listing flights:', error.response ? error.response.data : error.message);
        throw error;
    }
};

//增加酒店
export const addHotel = async (hotel) => {
    try {
        const response = await axios.post(BASE_URL, hotel, {
            headers: {
                'Content-Type': 'application/json'
            }
        });
        return response.data;
    } catch (error) {
        console.error('Error creating order:', error.response ? error.response.data : error.message);
        throw error;
    }
};

// 多条件搜索酒店
export const searchHotels = async (filters) => {
    try {
        const queryParams = new URLSearchParams(filters).toString();
        const response = await axios.get(`${BASE_URL}/search?${queryParams}`);
        return response.data;
    } catch (error) {
        console.error('Error searching hotels:', error.response ? error.response.data : error.message);
        throw error;
    }
};

//根据酒店地址查询
export const getHotelsByAddress = async (Address) => {
    try {
        const response = await axios.get(`${BASE_URL}/Address/${Address}`);
        return response.data;
    } catch (error) {
        console.error('Error listing flights:', error.response ? error.response.data : error.message);
        throw error;
    }
};

//根据酒店星级查询
export const getHotelsByStar = async (Star) => {
    try {
        const response = await axios.get(`${BASE_URL}/Star/${Star}`);
        return response.data;
    } catch (error) {
        console.error('Error listing flights:', error.response ? error.response.data : error.message);
        throw error;
    }
};

//根据酒店主题查询
export const getHotelsByTheme = async (Theme) => {
    try {
        const response = await axios.get(`${BASE_URL}/Theme/${Theme}`);
        return response.data;
    } catch (error) {
        console.error('Error listing flights:', error.response ? error.response.data : error.message);
        throw error;
    }
};

//根据酒店设施查询
export const getHotelsByFacilities = async (Facilities) => {
    try {
        const response = await axios.get(`${BASE_URL}/Facilities/${Facilities}`);
        return response.data;
    } catch (error) {
        console.error('Error listing flights:', error.response ? error.response.data : error.message);
        throw error;
    }
};